#include "internal.h"
#include "Defines.h"
#include "DeviceProperty.h"
#include "PortableDeviceProps.h"
#include "ObjectLock.h"
#include "SensorDdi.h"
#include "Sensor.h"
#include "SensorRegistry.h"
#include "Client.h"
#include "Client.tmh"

CClient::CClient(IWDFFile *pID)
{
	m_spClientID = pID;
}

bool CClient::AddSensor(CSensor *pSensor)
{
	//
	// add this sensor if it has not already been added
	//
	if(pSensor != NULL)
	{
		wstring id = pSensor->GetId();
		if(m_mapSensors.find(id) == m_mapSensors.end())
		{
			m_mapSensors[id] = pSensor;
			return true;
		}
	}

	return false;
}

bool CClient::AddSensor(LPWSTR pwszSensorID)
{
	return AddSensor(CSensorRegistry::GetSensorById(wstring(pwszSensorID)));
}

bool CClient::RemoveSensor(LPWSTR pwszSensorID)
{
	if(pwszSensorID != NULL)
	{
		if(m_mapSensors.find(pwszSensorID) != m_mapSensors.end())
		{
			m_mapSensors.erase(pwszSensorID);
			return true;
		}
	}

	return false;
}

CSensor *CClient::GetSensor(LPWSTR pwszSensorID)
{
	if(m_mapSensors.find(pwszSensorID) != m_mapSensors.end())
		return  m_mapSensors[pwszSensorID];
	return NULL;
}

ULONG CClient::GetSensorsCount()
{
	return (ULONG)m_mapSensors.size();
}
